home *** CD-ROM | disk | FTP | other *** search
/ Satanic Rites 3 / Satanic Rites - Issue 3 (1992-11-24)(Destiny).adf / coders / coders
Text File  |  1990-01-05  |  14KB  |  349 lines

  1.  {c +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2.  {c +++++     {e                Terminator's coding section.                  {c+++++
  3.  {c +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  4.  
  5.  {aThis time, I've dedicated the section to the more advanced amongst you.
  6.  I'm going to be talking about optimizations, fast tricks and more!
  7.  
  8.  The following optimizations, ideas, routines have come from many sources such
  9.  as disk magazines, hearsay, text files, experimentation etc.
  10.  
  11.  First some tricks from a text file found written by Turboslug/Digital
  12.  It looked like it was originally intended for publication in Stolen Data
  13.  anyway BUT seeing as they decided not to use this, we will!
  14.  Destiny got there first!
  15.  
  16.  A quick note to {eTurboslug/Digital{a
  17.  Hi Jamie,
  18.   Hope you dont mind us using this text but it seems such a waste of
  19.  your time and ideas. Also I hope you dont mind that I've corrected spelling
  20.  mistakes and reworded various paragraphs!
  21.  All the best m8.
  22.                        Terminator.
  23.  
  24.  Without further ado.... Take it away Jamie!
  25.  
  26.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  27.  {c+++++ {e                           FASTER BOBS!                           {c+++++
  28.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  29.  
  30.        {a  You need not leave that annoying 16 pixel gap to the right of your bobs!
  31.         This can be done by giving the BOB and BOB mask modulo a value of -2.
  32.         This means that when the blitter overshoots by 16 pixels and onto the
  33.         next line, the blitter module moves it back, and into the correct
  34.         position for the next line!  
  35.         The blitter channels MUST be used in this particular order.
  36.         A=Mask, B=Object and C=Screen this means that you can mask out all of
  37.         the overshoot rubbish by using blitter channel A, last word mask and
  38.         masking out all 16 pixels.
  39.         The masking of the mask in turn masks out the rubbish on the BOB!
  40.         This saves an inconvenience rather than raster time
  41.  
  42.  
  43.  
  44.  
  45.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  46.  {c+++++{e                            VERTICAL BLITTER FILL!                 {c+++++
  47.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  48.  
  49.     {a    Vertical, one pass, blitter fill!  The blitter has built into it a
  50.         horizontal filler, this can be activated by seting one of the bits 
  51.         in DMACON.  However sometimes you may want to do a vertical blitter
  52.         fill, to fill in an equalizer, cheat with a big sine scroller etc.
  53.  
  54.         This can be done, again with the blitter by simulating the horizontal
  55.         fill except vertically.  The blitter channels would be as follows.
  56.         A=Oldline, B=Line to fill where the minterms are as follows
  57.         00=0, 01=1, 10=1, 11=0 (logical EOR).
  58.         This could be done quite slowly, line by line with the blitter,
  59.         but using a blitter flaw the process can wrap in on it's self!
  60.         The flaw is that when the blitter copies downwards it overwrites
  61.         the memory it is copying.
  62.         Descending mode would usually be activated when this happens, but we
  63.         want it to reuse data from the previous line, so leave it in ascending
  64.         mode and the blitter will do a one pass vertical fill!
  65.         Blitter channel A starts by pointing to the first line of the area to
  66.         fill, and B the second.
  67.  
  68.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  69.  {c+++++{e                     AUTOMATIC PC RELATIVITY                      {c +++++
  70.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  71.  
  72.   {a      Here we go with Termy's theory of automatic relativity ...
  73.  
  74.         When using OPT A+ in DevPac, automatic PC relative mode addressing
  75.         an extension .L must be added to any reference which should remain
  76.         absolute.  This means that 
  77.  
  78.         {fLEA.L $DFF000,A5         ; creates an error!
  79.         LEA.L $DFF000.L,A5       ; doesn't!
  80. {a
  81.         Use PC relative addressing because it makes your code faster and
  82.         totally relocatable. Also it makes it two bytes shorter for every
  83.         occurrence of (pc) in your source.
  84.  
  85.         Another trick with PC relativity that most coders forget about is
  86.         to make all their jumps relative.
  87.  
  88.         I.e.
  89.       {f          OLD                             NEW
  90.         Jsr     MT_Init                   Jsr     MT_Init(PC)
  91.  
  92.     {a    This will also save you two bytes and also makes it relative to the
  93.         Program counter.
  94.  
  95.  
  96.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  97.  {c+++++{e                           QUICK FORM!                             {c+++++
  98.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  99.  
  100.   {a      I'm still seeing source codes with lame instructions such as...
  101.         Clr.l       d0       Dont be Lame! Use the faster psuedoops such as
  102.         Moveq.l     #0,d0.
  103.         clr.l       d0 uses 6 cycles whereas moveq.l #0,d0 uses 4.
  104.  
  105. {a        Some people say you should only use clr when you wish to preserve
  106.         the upper word of a longword
  107.         i.e.       assume d0 contains 12345678
  108.  
  109.         {fswap       d0  {e    ; make upper word lower and vice versa
  110.                            ; d0 is now 56781234
  111.         {fclr.w       d0   {e  ; clear lower word
  112.                            ; d0 is now 56780000
  113.         {fswap       d0    {e  ; swap back to normal.
  114.  
  115. {f        d0 will now contain 00005678.
  116.         The upper word has now been cleared.
  117.         The 3 instructions above took up 6 bytes of code.
  118.         Using the same amount of bytes, you can save 4 cycles.
  119.        
  120. {f        And.l       #$0000ffff,d0
  121.        
  122.   {a      That's it. 16 cycles in the first example and 12 in the second.
  123.  
  124. {a        A lot of coders forget about the Quick forms of addressing.
  125.         Some assemblers will tell you (e.g. DevPac)
  126.  
  127.         {e            Slow                    Fast!
  128.  
  129.       {f          Move.w  #1,d0           Moveq   #1,d0
  130.                 Add.w   #1,d0           Addq.w  #1,d0
  131.                 Sub.w   #1,d0           Subq.w  #1,d0
  132.                 Add.w   #1,a0           Addq.w  #1,a0
  133.                 Sub.w   #1,a0           Subq.w  #1,a0
  134.  
  135.     {a    As you may know, you cant moveq on an address register.
  136.         however, Move.w #0,a0 is automatically sign extended by the CPU
  137.         which uses 8 cycles. A faster way of clearing an address register
  138.         if you have a clear address register spare (E.g. a6) is to ...
  139.  
  140.   {f              Move.l  a6,Ax   ; 4 cycles
  141.  
  142.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  143.  {c+++++{e                        SHORT WORD ADDRESSING!                     {c+++++
  144.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  145.  
  146.  {aWhen referring to absolute addresses such as execbase,error vectors etc.
  147.  
  148.  {cDon't use
  149.  
  150.   {f              Move.l  4,a6
  151.  
  152.  {aUse short word addressing to your advantage! Use ...
  153.  
  154.   {f              Move.l  4.w,a6
  155.  
  156.  {aSimpler and shorter!
  157.  
  158.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  159.  {c+++++{e                     SPEED UP STATUS REGISTER ACCESS!              {c+++++
  160.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  161.  
  162.   {a      Another way of slowing down the processor is when checking the
  163.         status register. Although most coders very rarely use this,
  164.         here are the optimizations...
  165. {e
  166.                 Slow               Whoosh!                 Effect
  167.  
  168.   {f      Ori.b   #$4,ccr         Moveq   #0,d0           = Set 0 flag
  169.         Andi.b  #$ff-$04,ccr    Moveq   #1,d0           = Clear 0 flag
  170.         Ori.b   #$8,ccr         Moveq   #-1,d0          = Set negative flag
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  178.  {c++++{e                            FAST ANDING AND ORING!                  {c+++++
  179.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  180.  
  181.       {e          Slow!                                   Fast!
  182.  
  183.     {f   Move.w  d0,d1   ; 4 cycles              Moveq   #64,d1  ; 4 cycles
  184.        And.w   #64,d1  ; 8 cycles              And.w   d0,d1   ; 4 cycles
  185.  
  186.   {f     Move.w     d6,d7                        Moveq      #4,d7
  187.        Or.w       #4,d7   ; 12 cycles          Or.w       d6,d7    ; 8 cycles!
  188.  
  189. {a       both do exactly the same but the second is 4 cycles faster! Amazing eh?
  190.        Just simply faster addressing modes!
  191.  
  192.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  193.  {c+++++{e                     FAST MULTIPLICATION AND DIVISION!             {c+++++
  194.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  195.  
  196. {a       Many coders know how slow the mulu/muls instructions can be.
  197.        There are however several fast "cheats" to speed things up a bit.
  198.        one way, is if the number you are multiplying by is a power of 2
  199.        such as 2,4,8,16 etc. then use a left shift.
  200.  
  201.   {e               Slow!              Fast!
  202.     {f          Mulu #4,d0        Lsl.l #2,d0
  203.  
  204. {a       You can also speed up the divs / divu commands by shifting the
  205.        opposite directions.
  206.        However if the number of shift is less than 3 then its quicker to
  207.        use multiple additions.
  208.  
  209.      {e            Slow               Fast!           Faster!
  210.         {f      Mulu #4,d0         Lsl.l #2,d0    Add.l d0,d0
  211.                                                 Add.l d0,d0
  212.  
  213.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  214.  {c+++++{e                    FAST BIT OPERATIONS ON REGISTERS!              {c+++++
  215.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  216.  
  217.    {f    Bset       #2,d0                     Or.w       #4,d0       ; 12 > 8
  218.        (2x speed increase if or.w Dx1,Dx2)
  219.        Bchg       #2,d0                     Eor.w       #4,d0       ; 12 > 8
  220.        Bclr       #2,d0                     And.w       #4,d0       ; 12 > 8
  221.  
  222.  
  223.  
  224.  
  225.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  226.  {c+++++{e                            E.C.S. 60Hz                          {c  +++++
  227.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  228. {a
  229.  Okay! I think that's enough optimizations to keep you happy for a while!
  230.  Now for some simple things which I think you SHOULD know.
  231.  
  232.  I'm still seeing Lame ECS60Hz programs which fail to work properly even on a
  233.  Fatter agnus with 1mb.
  234.  The correct ways (As far as I am concerned) are as follows...
  235.  
  236.     {f   Move.w       #0,$dff1dc        ; Turn on ECS 60Hz
  237.        Move.w       #32,$dff1dc       ; Turn off ECS 60Hz
  238. {a
  239.  Note! This still won't work on most Tv's!
  240.  I've never seen any ECS emulator / activator work on my TV anyway!
  241.  Maybe I'm lacking an RGB signal which a monitor gives out or something!
  242.  
  243. {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  244. {c+++++           {e         Checking for E.c.s. presence.                  {c+++++
  245. {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  246. {a
  247.  I reckon its probably best to check if the computer the program is running
  248.  on has the ECS present.
  249.  The following routine returns 2 codes in d0 and d1 reporting what ECS chips
  250.  are present. The code represents....
  251.  
  252.  {ed0 -
  253.   {a     $0000   {f    =       Standard Pal Agnus{a
  254.        $1000     {f  =       Standard NTSC Agnus{a
  255.        $2000     {f  =       ECS Pal Agnus{a
  256.        $3000     {f  =       ECS Ntsc Agnus{a
  257.        
  258.  {ed1 -
  259.    {c    0    {f   =   {e    Standard Denise
  260.      {c  1     {f  =    {e   ECS Denise
  261.  
  262.  {aThe routine:
  263.   {f     Lea      $dff000,a5
  264.  ; Get agnus
  265.        Move.w   4(a5),d0
  266.        And.w    #$7f00,d0
  267.  ; Get Denise
  268.        Move.w   $f8(a5),d1
  269.        And.w    #$00ff,d1
  270.        Cmp.w    #$00fc,d1
  271.        Bne.s    standard
  272.        Moveq.l  #1,d1
  273.        Rts
  274.  standard
  275.        Moveq.l  #0,d1
  276.        Rts
  277.  
  278.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  279.  {c+++++  {e                   Software rebooting.                           {c+++++
  280.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  281.  
  282.  {aIs there a 100% official way of hard resetting ?
  283.  
  284.  {aHere are several versions that I know of ....
  285.  
  286. {f       move.w   #$4000,$dff09a
  287.        Move.l   #Rebootcode,$b4
  288.        Trap     #13
  289.  Rebootcode
  290.        move.w   #0,SR
  291.        Jmp      $fc0000
  292.  
  293.  {aVersion 2 ....
  294.  
  295.      {f  move.l   4.w,a6
  296.        lea      $fc00d0,a5
  297.        jmp      -$1e(a6)
  298.  
  299.  {aVersion 3 ....       {c(This version was in a commodore text file I)
  300. {f
  301.        move.l   4.w,a6
  302.        lea      reboot(pc),a5
  303.        jsr      _LVOsupervisor(a6)
  304.  
  305.        cnop     0,4
  306.  Reboot
  307.        lea.l    magic_romend,a0
  308.        sub.l    magic_sizeoffset(a0),a0
  309.        
  310.        move.l   4(a0),a0
  311.        
  312.        subq.l   #2,a0
  313.        
  314.        reset
  315.        jmp      (a0)
  316.  
  317.  {aWhat a load of shite eh ? None of them actually HARD reboot!
  318.  the only way I know of hard rebooting, (And this is the way most viruskillers
  319.  do it) is to clear all reset vectors and romtags before soft rebooting using
  320.  one of the above routines.
  321.  
  322.  {aAnyone know different ?
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  332.  {c+++++ {e                           THE END IS NIGH !                      {c+++++
  333.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  334.  {aWell that's about it for this issue, But if you have any ideas,problems
  335.  articles or anything else coding related, please write direct to the following
  336.  address:{f      Dave - Terminator
  337.                40,Heol Edward Lewis
  338.                Gelligaer
  339.                Hengoed
  340.                Mid Glamorgan
  341.                Cf8 8ej
  342.                South Wales
  343.  
  344.  {aOr send an {eE-Mail {amessage on EIS.
  345.  
  346.  
  347.  {fSee you next time !
  348.  {c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  349.